<script lang="ts" setup>
import HomePanel from './home-panel.vue'
import { useStore } from '@/store'
import { lazyApi } from '@/utils/vueuse'
import HomeSkeleton from './home-skeleton.vue'
// import { useIntersectionObserver } from '@vueuse/core'
// import { ref } from 'vue'
// const target = ref(null)
const { home } = useStore()
// const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
//   if (isIntersecting) {
//     // 接口懒加载：监听当前组件是否进入可视区域，进入就可始调用接口，且停止监听
//     home.homeNew()
//     stop()
//   }
// })
const target = lazyApi(home.homeNew)
</script>
<template>
  <div class="home-new" ref="target">
    <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
      <template #right>
        <XtxMore path="/"></XtxMore>
      </template>
      <!-- vue3动画:
      条件：进入/离开动作
        1:用transition包住
        2：加入name属性  name='xxx'
        .xxx-enter-active:进入过程中一直存在的class,主要用于承载transition/animation
        .xxx-enter-from:进入前状态，进入时希望从什么状态变到正常状态
        .xxx-leave-active:离开过程中一直存在的class,主要用于承载transition/animation
        .xxx-leave-to:离开时状态，离开时希望从正常状态变到什么状态
-->
      <transition name="move">
        <ul class="goods-list" v-if="home.newList.length">
          <li v-for="item in home.newList" :key="item.id">
            <RouterLink to="/">
              <img v-lazyImg="item.picture" alt="" />
              <p class="name ellipsis">{{ item.name }}</p>
              <p class="price">&yen;{{ item.price }}</p>
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton v-else></HomeSkeleton>
      </transition>
    </HomePanel>
  </div>
</template>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
